package com.ruoyi.syf.controller;

import java.util.Arrays;
import java.util.List;

import com.ruoyi.syf.domain.RiskAnalysisObject;
import com.ruoyi.syf.service.IRiskAnalysisObjectService;
import com.ruoyi.syf.handler.deleteChain.DeleteService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 安全分析对象
 *
 * @author yr
 * @date 2024-07-04
 */
@RestController
@RequestMapping("/syf/object")
public class RiskAnalysisObjectController extends BaseController {
    @Autowired
    private IRiskAnalysisObjectService riskAnalysisObjectService;

    @Autowired
    private DeleteService deleteService;

    /**
     * 查询安全分析对象列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RiskAnalysisObject riskAnalysisObject) {
        startPage();
        List<RiskAnalysisObject> list = riskAnalysisObjectService.list(riskAnalysisObject);
        return getDataTable(list);
    }

    /**
     * 获取安全分析对象详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(riskAnalysisObjectService.selectRiskAnalysisObjectById(id));
    }

    /**
     * 新增安全分析对象
     */
    @PreAuthorize("@ss.hasPermi('syf:object:add')")
    @Log(title = "安全分析对象", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskAnalysisObject riskAnalysisObject) {
        return toAjax(riskAnalysisObjectService.insertRiskAnalysisObject(riskAnalysisObject));
    }

    /**
     * 修改安全分析对象
     */
    @PreAuthorize("@ss.hasPermi('syf:object:edit')")
    @Log(title = "安全分析对象", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskAnalysisObject riskAnalysisObject) {
        return toAjax(riskAnalysisObjectService.updateRiskAnalysisObject(riskAnalysisObject));
    }

    /**
     * 修改安全分析对象状态
     */
    @PreAuthorize("@ss.hasPermi('syf:object:edit')")
    @Log(title = "安全分析对象", businessType = BusinessType.UPDATE)
    @PutMapping("/upStatus/{id}")
    public AjaxResult upStatus(@PathVariable("id") Long id, String reason) {
        return toAjax(riskAnalysisObjectService.upStatus(id, reason));
    }

    /**
     * 删除安全分析对象
     */
    @PreAuthorize("@ss.hasPermi('syf:object:remove')")
    @Log(title = "安全分析对象", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        deleteService.deleteObject(Arrays.asList(ids));
        return toAjax(true);
    }
}
